home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Video Toaster 4.0
/
Video Toaster v4.0.iso
/
arexx
/
cg
/
cghaiku.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1995-03-06
|
12KB
|
374 lines
/* A haiku generator CMD: Haiku */
/* from "Using ARexx on the Amiga" by Sullivan and Zamara */
/* CGized By Bob C. */
/* Adapted By Arnie */
/* Encrufted by Robert */
/* Tue Dec 1 22:45:53 1992 */
call addlib "CG_AREXX", 0
call InitVocab()
call random(,,time('s'))
page = GET_PAGE()
call SET_PAGE(NEXT)
if page_is_blank() then do
call SET_PAGE(TYPE,Framestore)
call GenHaiku()
end
else do
call KILLPAGE(page)
call SET_PAGE(TYPE,Framestore)
if page_is_blank() then
call GenHaiku()
end
page = GET_PAGE()
exit
/* GenHaiku
Generate and return a single Haiku poem
*/
GenHaiku:
/* Select a template, parse it into 3 lines, and clear output buffer. */
t = random(1,num_templates)
parse var tem.t line.1 '+' line.2 '+' line.3
out. = ''
/* Process template lines one at a time. */
do i=1 to 3
/* Keep going till template line exhausted. */
do while length(line.i) > 0
parse var line.i cmd 3 qual 4 line.i
c = left(cmd, 1)
ucmd = upper(cmd)
if v.ucmd ~= "" then do
w = word(v.ucmd, random(1, words(v.ucmd)))
if datatype(c, 'u') then
w = upper(left(w, 1))substr(w, 2)
upper c
if c='V' & qual='@' then
w = add_ing(w)
else if c='N' & qual='s' then
w = pluralize(w)
else
line.i = qual || line.i
end
else if c='/' then do
parse value cmd || qual || line.i with '/' list '/' line.i
w = word(list, random(1, words(list)))
end
else
parse value cmd || qual || line.i with w 2 line.i
out.i = out.i || w
end
end
out.1=translate(out.1,' ','_')
out.2=translate(out.2,' ','_')
out.3=translate(out.3,' ','_')
call MAKELINE(out.1)
call PICKLINE()
call SET_LINE(JUST,Center)
call MAKELINE(out.2)
call PICKLINE()
call SET_LINE(JUST,Center)
call MAKELINE(out.3)
call PICKLINE()
call SET_LINE(JUST,Center)
call PICKPAGE()
return
/* Add_Ing
Add the `ing' suffix to the given verb. The trick here is to double
the final consonant of the verb in many but not all instances. The
exception list and the code that employs take care of this. When new
verbs are added to the vocabulary lists, consider whether the `ing'
form is exceptional.
*/
add_ing: procedure
exc. = 0
exc.withdraw = 1
exc.wander = 1
exc.snarf =1
exc.wallow = 1
exc.flicker = 1
exc.shiver = 1
exc.wonder = 1
exc.edit = 1
exc.render = 1
exc.pay = 1
exc.eat = 1
exc.walk = 1
exc.shoot = 1
exc.fling = 1
exc.speak = 1
exc.flow = 1
exc.crawl = 1
exc.creep = 1
exc.reek = 1
exc.sink = 1
exc.croak = 1
exc.burn = 1
exc.stink = 1
exc.steal = 1
exc.peel = 1
exc.kill = 1
exc.toast = 1
exc.rent = 1
exc.drink = 1
exc.Smooth = 1
exc.Load = 1
exc.Stretch = 1
exc.Clear = 1
exc.Patch = 1
exc.Morph = 1
exc.destroy = 1
exc.accept = 1
exc.reboot = 1
exc.despair = 1
exc.descend = 1
exc.command = 1
exc.broadcast = 1
exc.shiver = 1
exc.Jitter = 1
exc.Mirror = 1
exc.Bevel = 1
exc.Align = 1
exc.encruft = 1
exc.command = 1
exc.splatter = 1
exv = upper(arg(1))
parse value arg(1) with 100 -3 l3 +1 l2 +1 l1
if index("mbgprndlt",l1)>0 & index("aeiou",l2)>0 & index("aeiou",l3)=0 then do
if ~exc.exv then
w = arg(1) || l1
else
w = arg(1)
end
else if l1='e' then
w = left(arg(1), length(arg(1)) - 1)
else
w = arg(1)
return w || 'ing'
/* Pluralize
Pluralize the given word, taking account of certain exceptions. If you
add nouns to the vocabulary lists, consider whether the pluralization
is exceptional.
*/
pluralize: procedure expose v.
exc. = 0
exc.ice = 1
exc.beach = 1
exc.spooge = 1
exc.kluge = 1
exc.mouse = 1
exc.moose = 1
exc.bass = 1
exc.box = 1
exc.peach = 1
exc.glance = 1
exc.bus = 1
exc.juice = 1
exc.paintbox = 2
exc.Image = 2
exc.Sequence = 2
exc.lotus = 2
exc.gecko = 10
exc.cry = 11
exc.dei = 12
w = arg(1)
uw = upper(w)
/* Nouns with an exception code of 1 or 2 have 1 or 2 syllables
respectively in the singular, but an extra syllable in the plural.
Since the syllables must remain constant, we replace such a noun
with another from its list, until we find one that is not lengthened
by pluralization.
*/
do while exc.uw > 0 & exc.uw < 10
list = value('v.n'exc.uw)
w = word(list, random(1, words(list)))
uw = upper(w)
end
/* Match capitalization of argument word with (possibly) new word. */
if datatype(left(arg(1),1),'u') then
w = upper(left(w,1))substr(w,2)
/* Pluralize */
select
when exc.uw = 0 then w = w || 's'
when exc.uw = 10 then w = w || 'es'
when exc.uw = 11 then w = left(w,2) || 'es'
otherwise
call inform("Invalid pluralize exception" exc.uw)
exit
end
return w
InitVocab:
v. = ""
/* Adjectives, one syllable */
av.a1 = "quick wild small hot white wet blue pink old light dark"
v.a1 = v.a1 "sad deep lost free drunk slow dumb hard soft damp dry"
v.a1 = v.a1 "tight loose gross cold clean proud dead plaid munged nuked"
v.a1 = v.a1 "strong weak young dull ill mean flat sharp kluged tweaked"
v.a1 = v.a1 "wudge freak"
/* Adjectives, two syllables */
v.a2 = "evil putrid empty crooked runny fallen dismal crufty"
v.a2 = v.a2 "potent rabid gnarly golden hairy wrinkled cuspy"
v.a2 = v.a2 "robust rancid smiling toasted paisley dying measly"
v.a2 = v.a2 "brain_dead stupid plastic bogus lo-res frothy 3D hi-res"
v.a2 = v.a2 "opaque diffuse default wireframe print-res angry flattened"
/* Nouns, one syllables */
v.n1 = "goat moose cat stream kluge fade mouse sprite bomb bass disc box"
v.n1 = v.n1 "worm hack moon dog glance flame spooge cow pig shell cone Fudd"
v.n1 = v.n1 "frob Spam curve spline clone duck sea hand fish neck growth ice"
v.n1 = v.n1 "point sync deck cop food RAM wine beer car bus bike juice ball"
v.n1 = v.n1 "box light scene key bone frame fog sky ground view stat Duff"
/* Nouns, two syllables */
v.n2 = "shadow forest guitar keyboard missile toaster teapot pointer guru"
v.n2 = v.n2 "ooblick chomper dissolve parrot budgie info volume red_head"
v.n2 = v.n2 "CD valley switcher cookie framestore farmer hard_disk wetware"
v.n2 = v.n2 "Toaster LightWave model object cheese_shop option splitter"
v.n2 = v.n2 "CG starship airport sports_car pudding oatmeal layout weasel wirehead"
v.n2 = v.n2 "image preview shadow bump_map color segment motion widget"
v.n2 = v.n2 "lens_flare spot_light backdrop zenith nadir program hacker"
v.n2 = v.n2 "Flyer Screamer Rapter"
/* Verbs, one syllable */
v.v1 = "walk eat grab shoot fling frag stick speak flow live cut paste"
v.v1 = v.v1 "rip crawl creep reek bite sink take croak burn stop stink flip"
v.v1 = v.v1 "spit shine steal fade peel crave kill stab writhe split"
v.v1 = v.v1 "dub toast tape cut rent burn shop chomp pay drink eat snore"
v.v1 = v.v1 "make smooth load save clear lathe blast ride"
v.v1 = v.v1 "clone skin morph grok mung phreak count nuke snarf"
/* Verbs, two syllables */
v.v2 = "explode desire adlib destroy decline accept dissolve endure reboot"
v.v2 = v.v2 "rebel retire despair encode wonder bubble flicker grumble"
v.v2 = v.v2 "decode descend compile command render edit broadcast shiver wallow"
v.v2 = v.v2 "jitter combine copy bevel rotate splatter command withdraw"
v.v2 = v.v2 "align extrude mirror flatline encruft guru"
/* Verbs, one syllable, transitive */
v.v3 = "eat grab shoot cut rip bite sink take burn stop flip steal peel crave"
v.v3 = v.v3 "stab split scream toast chomp drink save blast ride clone mung"
v.v3 = v.v3 "snarf nuke kill find own lose keep know see smell hear taste feel"
/* Verbs, one syllable, transitive, past tense */
v.t1 = "ate killed shot cut bit sank burned stopped stole found lost smashed"
v.t1 = v.t1 "chomped drank munged nuked snarfed took boned"
/* Prepositions, one syllable */
v.p1 = "on of in near past at by in through from"
/* Prepositions, two syllables */
v.p2 = "left_of upon under beside over west_of beyond above below around"
v.p2 = v.p2 "inside outside next_to far_from behind"
/* Relative adverbs, one syllable */
v.r1 = "where when while as"
/* Little words that can precede nouns, biased towards `the' */
v.l1 = "the God's Hell's this my Bob's your his her the Ken's Ron's Moe's"
v.l1 = v.l1 "Skell's Mark's Paul's Tim's James' Dawn's Penn's its our the Wil's"
v.l1 = v.l1 "Kirk's Spock's Worf's Q's Croooow's Joel's Bart's Dreux's"
v.l1 = v.l1 "Death's Jud's Dan's Dick's some all Ren's Charles' Anne's Steve's"
v.l1 = v.l1 "Grue's Chuck's Gregs's Chris's Todd's Simba's Nala's Brad's"
v.l1 = v.l1 "Greg's Grue's Bob's Lloyd's"
/* Names, two syllables */
v.h2 = "Robert NewTek Pink_Floyd Tami Smithers Billy Flanders Londo"
v.h2 = v.h2 "David Yoko Arnie Satan Jesus Homer Kerri Barney"
v.h2 = v.h2 "Ervin Batman Robin Mofo some_jerk James_Bond"
v.h2 = v.h2 "Kiki Simone Lobo Ayn_Rand John_Cleese Elvis Allen"
v.h2 = v.h2 "Peter Kenbe Junior Daniel Teller Kristy Kelly Stuart"
v.h2 = v.h2 "Dana Picard Riker Data Geordi Crusher Milhouse Apu Laura Tammy"
v.h2 = v.h2 "Cambot Gypsy Alex Bobbi Lisa Maggie Porter Stephen Mojo Stimpy"
v.h2 = v.h2 "JoJo Jason"
/* Haiku templates
The special tokens in the templates are:
a1,n2 etc. Part of speech, replaced randomly from corresponding list
A1,N2 etc. Same, but with initial capital
+ Converted to linefeed
@ After verb, specifies conversion to `ing' (gerund) form
s After noun, specifies conversion to plural form
/wordlist.../ Replaced by a word picked randomly from the list
All other symbols in the templates are taken literally.
*/
tem. = ""
tem.1 = "A1 n1, a2 n1.+L1 a1, a2 n2 v1s.+A1 n1, a1 n2."
tem.2 = "P2 the a1 n1,+R1 the a2 n2 v1s,+I v1; the n1 v1s."
tem.3 = "The a1 n1 v1@;+It is the a2 n2.+V2@, I v1."
tem.4 = "The a2 n1 v1s+R1 a2 n2s v2.+Does the a1 n1 v1?"
tem.5 = "Not a1, but a2,+H2 comes to the n2.+L1 a1 n2 v1s."
tem.6 = "A1, a2, a2,+H2 v1s. H2 v2s,+V2@, v1@."
tem.7 = "/Never Sometimes/ a1, but a1,+H2 knows /no my some all/ a1 n2s.+A2, /he she/ v2s."
tem.8 = "/Not Quite/ a1, /and but or/ a2,+H2 comes to the n2.+L1 a1 n2 v1s."
tem.9 = "A1 n1, a2 n1.+L1 a1, a2 n2 v1s.+A1 n1, a1 n2."
tem.10 = "The a2 n1 v1s +R1 a2 n2s v2.+Does the a1 n1 v1?"
tem.11 = "Not a1, but a2,+H2 comes to the n2.+L1 a1 n2 v1s."
tem.12 = "A1, a2, a2,+H2 v1s. H2 v2s,+V2@, v1@."
tem.13 = "Hey! Get back to work +You lazy, no good n2. +The world is v1@!"
tem.14 = "If n2s could v1, +And v3 l1 n2 today, +The n1 would v3 you."
tem.15 = "If n2s could v1, +And v3 l1 n2 today, +The n1 would v3 you."
tem.16 = "As the n1 draws near, +H2 v3s our n1. You must +V3 the a1 n2."
tem.17 = "Alone the a1 n1 v1s. +'Where is my n2?', you ask. +/Ack! Doh! Oops!/ H2 t1 it."
tem.18 = "Attention all n1s! +When v1@ n2s v2, +It's time to v2."
do i=1 while tem.i ~= ""
end
num_templates = i - 1
return
syntax:
error:
t=REQ_TELL('Rexx Script Error')
exit
page_is_blank:
page_size=GET_PAGE(SIZE)
line_size=GET_LINE(SIZE)
if (page_size = 0 | page_size = 1) & line_size = 0 then
return 1
else
return 0